<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link rel="stylesheet" href="./framework/font-awesome-4.7.0/css/font-awesome.min.css">
		<link rel="stylesheet" href="./framework/reset.css">
		<link rel="stylesheet" href="./framework/common.css">
		<title>东软环保公众监督系统-公众监督员端-注册</title>
		<script src="../js/axios.js"></script>
	</head>
	<body>
		<!-- 总容器 -->
		<div class="wrapper">
			<div class="header-box">
				<header>
					<i class="fa fa-angle-left" onclick="history.go(-1)"></i>
					<p>注册</p>
					<i></i>
				</header>
				<div class="top-ban"></div>
				<img src="./img/header.png">
			</div>

			<table class="table-form">
				<tr>
					<td>手机号码</td>
					<td><input id="telId" type="text" placeholder="请输入手机号码"></td>
				</tr>
				<tr>
					<td>真实姓名</td>
					<td><input id="realName" type="text" placeholder="真实姓名便于我们联系您"></td>
				</tr>
				<tr>
					<td>出生日期</td>
					<td><input id="birthday" type="date" placeholder="出生日期"></td>
				</tr>
				<tr>
					<td>性别</td>
					<td>
						<input id="sex" name="sex" type="radio" checked>男
						<input name="sex" type="radio">女
					</td>
				</tr>
				<tr>
					<td>密码</td>
					<td><input id="password" type="password" placeholder="请输入密码"></td>
				</tr>
				<tr>
					<td>确认密码</td>
					<td><input id="relPassword" type="password" placeholder="请再次输入密码"></td>
				</tr>
				<tr>
					<td colspan="2">
						<div class="btn" onclick="register();">注册</div>
					</td>
				</tr>
			</table>
		</div>
	</body>
	<script>
		function register() {
			let telTest = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
			let telId = document.getElementById("telId").value;
			let realName = document.getElementById("realName").value;
			let birthday = document.getElementById("birthday").value;
			let password = document.getElementById("password").value;
			let relPassword = document.getElementById("relPassword").value;
			let sexNan = document.getElementById("sex").value;
			let sex = 0;
			if (sexNan.checked) {
				sex = 1;
			}
			if (telTest.test(telId) < 0) {
				alert("手机号输入不正确");
			}
			if (realName == null || realName == "") {
				alert("真实姓名不能为空");
			}
			if (birthday == null || birthday == "") {
				alert("出生日期不能为空");
			}
			if (password == null || password == "") {
				alert("密码不能为空");
			}
			if (relPassword == null || relPassword == "") {
				alert("确认密码不能为空");
			}
			if (password != relPassword) {
				alert("密码与确认密码不一致");
			}
			let url = "http://localhost:8080/supervisor/register";
			axios.post(url, {
				telId: telId,
				realName: realName,
				birthday: birthday,
				password: password,
				sex: sex
			}).then((r) => {
				switch (r.data) {
					case 0:
						alert("注册失败");
						break;
					case 1:
						alert("注册成功");
						location.href = "./login.html";
						break;
					case -1:
						alert("该手机号已注册");
						break;
				}
				console.log(r)
			})
		}
	</script>
</html>